//
//  VisitorLoginView.swift
//  SinWebo
//
//  Created by 刘大钊 on 16/4/13.
//  Copyright © 2016年 刘大钊. All rights reserved.
//

import UIKit
import SnapKit

class VisitorLoginView: UIView {

    //首先要自定义视图 首先找到入口
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        //访客视图的自定义
        setUpUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: 自定义访客视图
    private func setUpUI(){
        
        addSubview(circleIcon)
        addSubview(maskImage)
        addSubview(largeHouse)
        addSubview(tipLable)
        addSubview(loginBtn)
        addSubview(registerBtn)
        
        //1.item:需要添加约束的对象
        //2.attribute：对象需要添加约束的属性
        //3.relatedBy:对齐方式 一定要使用精准约束的方式
        //4.toItem：布局相对应的视图 参照视图
        //5.attribute：参照对象约束属性
        //6.multiplier：乘积系数 一般使用 1 
        //7.constant：约束的偏移量
        
        //在手写代码添加自动布局约束对象时候 需要禁用frame布局
//        circleItem.translatesAutoresizingMaskIntoConstraints = false
//        largeHouse.translatesAutoresizingMaskIntoConstraints = false
//        
//        self.addConstraint(NSLayoutConstraint(item: circleItem, attribute: NSLayoutAttribute.CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1, constant: 0))
//        self.addConstraint(NSLayoutConstraint(item: circleItem, attribute: NSLayoutAttribute.CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0))
//        
//        self.addConstraint(NSLayoutConstraint(item: largeHouse, attribute: NSLayoutAttribute.CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1, constant: 0))
//        self.addConstraint(NSLayoutConstraint(item: largeHouse, attribute: NSLayoutAttribute.CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0))
        
        circleIcon.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-80)
        }
        largeHouse.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(circleIcon.snp_center)
        }
        tipLable.snp_makeConstraints{ (make) -> Void in
            make.centerX.equalTo(circleIcon.snp_centerX)
            make.top.equalTo(circleIcon.snp_bottom).offset(16)
        }
        loginBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(tipLable.snp_left)
            make.top.equalTo(tipLable.snp_bottom).offset(16)
            make.width.equalTo(100)
        }
        registerBtn.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(tipLable.snp_right)
            make.top.equalTo(tipLable.snp_bottom).offset(16)
            make.width.equalTo(100)
        }
        maskImage.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(circleIcon.snp_center)
        }
        let value : CGFloat = 236.0 / 255.0
        backgroundColor = UIColor(red: value, green: value, blue: value, alpha: 1)
        
    }
  
    
    //懒加载子视图
    
    //遮罩视图
    private lazy var maskImage:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    
    private lazy var circleIcon:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    //大房子
    private lazy var largeHouse:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    private lazy var tipLable: UILabel = {
        let l = UILabel()
        l.text = "关注一些人,回到这里看看有什么惊喜"
        l.textColor = UIColor.darkGrayColor()
        l.font = UIFont.systemFontOfSize(14)
        
        //自适应大小
        l.sizeToFit()
        return l
        
    }()
    
    //登录和注册按钮
    private lazy var loginBtn: UIButton = {
        let btn = UIButton()
        //这是背景图片
        let image = UIImage(named:"common_button_white_disable")!
        let capW = Int(image.size.width * 0.5)
        let capH = Int(image.size.height * 0.5)
        
        btn.setBackgroundImage(image.stretchableImageWithLeftCapWidth(capW, topCapHeight: capH), forState: .Normal)
        btn.setTitle("登录", forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        btn.sizeToFit()
        return btn
        
    }()
    
    private lazy var registerBtn: UIButton = {
        let btn = UIButton()
        //这是背景图片
        btn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: .Normal)
        btn.setTitle("注册", forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        btn.sizeToFit()
        return btn
        
    }()
    
}
